package com.ruoyi.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.MineLtcdjc;
import com.ruoyi.domain.SysCoalMachine;
import com.ruoyi.domain.dto.SysCoalMachineDto;
import com.ruoyi.domain.vo.SysCoalMachineVo;
import com.ruoyi.mapper.MineLtcdjcMapper;
import com.ruoyi.service.MineLtcdjcService;
import com.ruoyi.service.SlopeMonitorService;
import com.ruoyi.utils.WeiteTxtFileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@RestController
@RequestMapping("/slope/monitoring")
public class SlopeMonitorController {
    @Autowired
    private SlopeMonitorService slopeMonitorService;
    @Autowired
    private MineLtcdjcService mineLtcdjcService;

    @Autowired
    private WeiteTxtFileUtils weiteTxtFile;

    @GetMapping("/systxt")
    public Boolean sysCoalMachineTxt() {
        slopeMonitorService.slopeMonitorcreateTxt();
        return true;
    }

    @GetMapping("/minetxt")
    public Boolean mineLrcdjcTxt() {
        mineLtcdjcService.mineLtcdjcCreateTxt();
        return true;
    }


    //    @Log(title = "主机管理", businessType = BusinessType.INSERT)
    @PostMapping
    public Boolean add(@RequestBody SysCoalMachineDto sysCoalMachineDto) {
        return slopeMonitorService.insertMachine(sysCoalMachineDto);
    }

    @Log(title = "主机管理", businessType = BusinessType.INSERT)
    @PostMapping("/update")
    public Boolean update(@RequestBody SysCoalMachineDto sysCoalMachineDto) {
        return slopeMonitorService.updateMachine(sysCoalMachineDto);
    }

    @GetMapping("/query")
    public void query() throws ClassNotFoundException {
//        String hHmmss = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
//        String wejianmin= "123231212"+"_"+"sdada"+"_"+hHmmss+".txt";
//
//        String a =MINE_PATH +wejianmin;
//       // List<MineLtcdjc>  set = mineLtcdjcMapper.set();
//        MineLtcdjc ltcdjc = set.get(0);
//        String string = ltcdjc.toString();
//
//        File file = new File(MINE_PATH);
//
//
//        if (!file.exists()){
//            if (file.mkdirs()){
//                System.out.println("创建目录");
//                weiteTxtFile.add(a,string,set);
//            }else {
//                System.out.println("chuan失败");
//            }
//        }else {
//            weiteTxtFile.add(a,"13028403001+",set);
//        }

    }

}
